<!DOCTYPE html>
<html class="loading" lang="en" data-textdirection="ltr" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=0, minimal-ui">
    <meta name="author" content="PIXINVENT">
    <title>企业人事管理后台</title>
    <link rel="stylesheet" type="text/css" th:href="@{/app-assets/css/vendors.css}">
    <link rel="stylesheet" type="text/css" th:href="@{/app-assets/css/vertical-menu.css}">
    <link rel="stylesheet" type="text/css" th:href="@{/app-assets/css/bootstrap-extended.css}">
</head>

<body>
<div class="content-wrapper">
    <div class="content-header ">
        <div class="content-header-left mb-2">
            <h3 class="content-header-title mb-0">系统公告</h3>
        </div>
    </div>

    <div class="card">
        <div class="card-content">
            <div class="card-body">
                <div class="searchbox">
                    <form class="form-inline" th:action="@{/declare}" th:object="${declare}" method="get">
                        <div class="form-group">
                            <input type="text" class="form-control" th:field="*{title}" placeholder="请输入公告标题">
                        </div>
                        <!--                        <div class="form-group">-->
                        <!--                            <input type="text" class="form-control" th:field="*{declareName}" placeholder="请输入发布人">-->
                        <!--                        </div>-->
                        <div class="form-group">
                            <button type="submit" class="btn btn-primary">查询</button>
                        </div>
                    </form>
                </div>
                <div class="funcbtn clearfix">
                    <button type="submit" class="btn btn-success" onclick="add()">增加</button>
                </div>
                <div class="tablebox1">
                    <table class="table">
                        <thead>
                        <tr>
                            <th>标题</th>
                            <th>发布人</th>
                            <th>备注</th>
                            <th>发布时间</th>
                            <th>操作</th>
                        </tr>
                        </thead>
                        <tbody>
                        <tr th:each="el : ${pageInfo.getList()}">
                            <td th:text="${el.title}"></td>
                            <td th:text="${el.declareName}"></td>
                            <td th:text="${el.declarePeople}"></td>
                            <td th:text="${#dates.format(el.declareTime,'yyyy-MM-dd')}"></td>
                            <td>
                                <a href="#" class="btn btn-primary btn-td" th:data-id="${el.id}"
                                   onclick="edit(this.getAttribute('data-id'))">修改</a>
                                <!--                      th:href="@{'/attendance_management/delete/' + ${el.attendanceId}}"-->
                                <a href="#" class="btn btn-danger btn-td" th:del-id="${el.id}"
                                   onclick="del(this.getAttribute('del-id'))">删除</a>
                            </td>
                        </tr>
                        </tbody>
                    </table>

                    <div class="page clearfix">
                        <div class="pull-left"
                             th:text="|共  ${pageInfo.getTotal()} 条记录 第 ${pageInfo.getPageNum() } / ${pageInfo.getPages()} 页|"></div>
                        <div class="pull-right">

                            <nav aria-label="..." class="pull-left">
                                <ul class="pagination" th:each=" el : ${pageInfo.getNavigatepageNums()}"
                                    th:switch="${el}">
                                    <!--                                    <li class="disabled"><a href="#" aria-label="Previous"><span-->
                                    <!--                                            aria-hidden="true">«</span></a></li>-->
                                    <li th:case="1" class="active"><a
                                            th:href="@{'/contract?pageSize=' + ${el}}" th:text="${el}"></a>
                                    </li>
                                    <li th:case="*"><a th:href="@{'/contract?pageSize=' + ${el}}"
                                                       th:text="${el}"></a></li>
                                    <!--                                    <li><a href="#" aria-label="Next"><span aria-hidden="true">»</span></a></li>-->
                                </ul>
                            </nav>

                            <div class="pull-left p-r-20  p-l-20"><select class="form-control">
                                <option>10条每页</option>
                            </select></div>
                        </div>
                    </div>
    </div>
</div>


<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span
                        aria-hidden="true">&times;</span></button>
                <h4 class="modal-title1" id="modal-title1"> 修改用户信息</h4>
            </div>
            <from id="myForm" name="myForm">
                <div class="modal-body">
                    <div class="form1 from2">
                        <ul class="row">
                            <li class="col-xs-10">
                                <span>标题：</span>
                                <input type="text" class="form-control" name="title" id="edit_title" value="">
                            </li>
                            <li class="col-xs-10">
                                <span>发布人：</span>
                                <input type="text" class="form-control" id="edit_declareName" value="">
                            </li>
                            <li class="col-xs-10">
                                <span>备注：</span>
                                <input type="text" class="form-control" id="edit_declarePeople" value="">
                            </li>
                            <li class="col-xs-10">
                                <span>时间：</span>
                                <input type="datetime-local" class="form-control" id="edit_declareTime" value="">
                            </li>
                        </ul>
                        <input type="number" class="form-control" style="display: none;" id="edit_id" value="">
                    </div>
                </div>
            </from>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
                <button type="button" class="btn btn-primary" onclick="save()">保存</button>
            </div>
        </div>
    </div>
</div>






</div>

<script src="../../../static/app-assets/js/vendors.min.js" type="text/javascript"></script>
<script src="../../../static/app-assets/js/app-menu.js" type="text/javascript"></script>
<script src="../../../static/app-assets/js/app.js" type="text/javascript"></script>
<script src="../../../static/app-assets/js/echarts.min.js" type="text/javascript"></script>
<script src="app-assets/js/vendors.min.js" type="text/javascript"></script>
<script src="app-assets/js/app-menu.js" type="text/javascript"></script>
<script src="app-assets/js/app.js" type="text/javascript"></script>
<script src="app-assets/js/echarts.min.js" type="text/javascript"></script>


<script th:inline="javascript">

    $(document).ready(function () {
        $(".ewm").click(function () {
            $(this).toggleClass("active")
        });
    });

    function add() {
        document.getElementById('modal-title1').innerText = '新增公告信息'
        document.getElementById('edit_title').value = ''
        document.getElementById('edit_declareName').value = ''
        document.getElementById('edit_declarePeople').value = ''
        document.getElementById('edit_declareTime').value = ''
        $('#myModal').modal('show')
    }

    function save() {
        let params = {
            title: document.getElementById('edit_title').value,
            declareName: document.getElementById('edit_declareName').value,
            declarePeople: document.getElementById('edit_declarePeople').value,
            declareTime: document.getElementById('edit_declareTime').value,
            id: document.getElementById('edit_id').value,
            declareLimit: 0
        }
        console.log(params);
        if (params.id === null || params.id === '' ||  params.id === undefined) {
            $.post('declare/insert', params, function (e, d) {
                $('#myModal').modal('hide')
                location.reload();
            });
        } else {
            console.log("更新")
            $.post('declare/update', params, function (e, d) {
                $('#myModal').modal('hide')
                location.reload();
            });
        }

    }


    function edit(id) {
        document.getElementById('modal-title1').innerText = '修改公告信息'
        $.get('/declare/selectById/' + id, function (e, d) {

            document.getElementById('edit_title').value = e.title
            document.getElementById('edit_declareName').value = e.declareName
            document.getElementById('edit_declarePeople').value = e.declarePeople
            document.getElementById('edit_declareTime').value = e.declareTime
            document.getElementById('edit_id').value = e.id
            $('#myModal').modal('show')
        })
    }

    function del(id) {
        var x;
        var r = confirm("请确认是否删除该数据！");
        if (r === true) {
            $.get('/declare/delete/' + id, function (e, d) {
                location.reload();
            })
        }
    }

</script>

</body>
</html>
